package edu.sctu.fengleilin.month06.day150628.SecondPractice;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
* Created by user09 on 2015/6/28.
*/
public class UrlThread extends Thread {

    @Override
    public void run() {
        String json ="";

        try {
            System.out.println("Please wait for 5 seconds,thank you!");
            Thread.sleep(5000);

            URL url = new URL("http://api.ii.com.cn/goods/apprec");

            URLConnection connection = url.openConnection();
            int count;
            byte[] buffer = new byte[1024];
            InputStream inputStream = connection.getInputStream();

            FileOutputStream outputStream = new FileOutputStream(new File("D://json//json.txt"));
            while (( count = inputStream.read(buffer)) != -1) {
                outputStream.write(buffer,0,count);
             }

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }


}
